package com.ra.landlord.vo;

import java.io.File;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.googlecode.cswish.annotation.cm;
import com.ra.landlord.Agreement;
import com.ra.landlord.Fee;
import com.ra.landlord.FeeRecord;
import com.ra.landlord.FeeRuleCfg;
import com.ra.landlord.LandlordOwnerUser;
import com.ra.landlord.LandlordUser;
import com.ra.landlord.TenantUser;

/**
 * DA、RA合约
 * 
 * @author colin Date: 2015-09-14
 */
public class AgreementVO {

	private Integer id;
	
	private String roomName;
	
	private Integer roomId;
	
	// 房源类型(ROOMTYPE_DA = 0;ROOMTYPE_RA = 1;)
	private Integer roomType;
	
	private String roomImageSrc;
	
	private String address;
	
	private String floorName;
	
	// 押金
	private BigDecimal deposit;
	
	// 租金
	private BigDecimal rentPay;
	
	// 订金
	private BigDecimal bookPay;
	
	// 租期
	private String rentPeriod;
	
	// 起租日期
	private Date rentBeginDate;
	
	// 到期日期
	private Date rentEndDate;
	
	//押付模式（0:一押一付；1:两押一付；2：三押一付；3：四押一付；）
	private Integer rentType;
	
	// 收费周期类型：月；年
	private Integer rentCycleType;
	
	// 收费周期：一个月；半年；一年
	// 从0开始, 0-11表示1,2,3个月等等
	private Integer rentCycle;
	
	//出租方式（0：自然月；1：租赁月）
	// 出租方式: 0,自然月；1,租赁月
	private Integer rentMode;
	
	// 自然月开始结束时间
	private String modeDt;
	
	// 合约有效, 只读属性, 其修改由DiscriminatorColumn决定
	private Integer agreementState;
	
	// 换房信息
	private String changeInfo;
	
	// 备注
	private String remark;
	
	// 经办人
	private LandlordUser agent;
	
	//费用增长类型（0表示不使用）
	// 费用增长类型
	private Integer rentGrowthType;
	
	// 费用增长的金额
	private String rentGrowthMoney;
	
	private LandlordOwnerUser landlordUser;
	
	// (冗余字段，数据对应Fee的balance)余额， 为正表示有存， 负表示还有欠缴
	private BigDecimal balance;
	
	//合约下的费用
	private List<Fee> fees;
	
	private Integer status;
	
	@cm("付款方式  押几")
	private Integer depositNum;
	
	@cm("付款方式  付几") //交租日期=起租日期+付几月  -提前多天
	private Integer payNum;
	
	@cm("提前多少天 付款")
	private Integer advanceNum;
	
	@cm("租期")
	private Integer tenancy;
	
	@cm("租期类型：月、年")
	private Integer tenancyType;
	
	//transient
	private File photo;
	
	@cm("合约照片")
	private String photoFileName;
	
	//@Transient 其他费用总额
	private BigDecimal fixedFeeTotalAmount;
	
	//@Transient
	private FeeRecord lastFeeRecord;
	
	// 租客
	private TenantUser tenantUser;
	
	//面积
	private BigDecimal area;
	
	//费用项
	private List<FeeRuleCfg> feeRuleCfgs;
	
	// 是否存在未缴费的订单
	private Boolean hasTodoOrder;
	
	private Integer rentalOrderId;

	public Integer getRentalOrderId() {
		return rentalOrderId;
	}

	public void setRentalOrderId(Integer rentalOrderId) {
		this.rentalOrderId = rentalOrderId;
	}

	public Boolean getHasTodoOrder() {
		return hasTodoOrder;
	}

	public void setHasTodoOrder(Boolean hasTodoOrder) {
		this.hasTodoOrder = hasTodoOrder;
	}

	public List<FeeRuleCfg> getFeeRuleCfgs() {
		return feeRuleCfgs;
	}

	public void setFeeRuleCfgs(List<FeeRuleCfg> feeRuleCfgs) {
		this.feeRuleCfgs = feeRuleCfgs;
	}

	public BigDecimal getArea() {
		return area;
	}

	public void setArea(BigDecimal area) {
		this.area = area;
	}

	public TenantUser getTenantUser() {
		return tenantUser;
	}

	public void setTenantUser(TenantUser tenantUser) {
		this.tenantUser = tenantUser;
	}
	
	public String getFloorName() {
		return floorName;
	}

	public void setFloorName(String floorName) {
		this.floorName = floorName;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public void adaptRentPeriodNew()
	{
		if (this.tenancy != null)
		{
			int rentCycleMonth = (Agreement.TENANCY_TYPE_YEAR.equals(this.tenancyType)) ? this.tenancy * 12 : this.tenancy;
			this.rentPeriod = String.valueOf(rentCycleMonth);
			this.rentCycleType = Agreement.RENT_CYCLE_TYPE_MONTH;
		}
	}

	/**
	 * 兼容新字段: 压付模式 (老适配新)
	 */
	public void adaptRentType()
	{
		if (this.rentType == null)
		{
			return;
		}
		
		switch (this.rentType) 
		{
		case 0:
			adaptRentTypeSet(1, 1);
			break;
		case 1:
			adaptRentTypeSet(2, 1);
			break;
		case 2:
			adaptRentTypeSet(3, 1);
			break;
		case 3:
			adaptRentTypeSet(4, 1);
			break;
		case 4:
			adaptRentTypeSet(1, 2);
			break;
		case 5:
			adaptRentTypeSet(2, 2);
			break;
		case 6:
			adaptRentTypeSet(3, 2);
			break;
		case 7:
			adaptRentTypeSet(4, 2);
			break;
		case 8:
			adaptRentTypeSet(1, 3);
			break;
		case 9:
			adaptRentTypeSet(2, 3);
			break;
		case 10:
			adaptRentTypeSet(3, 3);
			break;
		case 11:
			adaptRentTypeSet(4, 3);
			break;

		default:
			adaptRentTypeSet(1, 1);
			break;
		}
	}
	
	/**
	 * 兼容老字段: 压付模式(新适配老)
	 */
	public void adaptRentTypeNew()
	{
		if (this.depositNum == null)
		{
			return;
		}
		
		int pay = this.payNum;
		switch (this.depositNum) 
		{
		case 1:
			if (pay == 1)
			{
				setRentType(0);
			}
			else if (pay == 2)
			{
				setRentType(4);
			}
			else if (pay == 3)
			{
				setRentType(8);
			}
			else
			{
				setRentType(8);
			}
			
			break;
		case 2:
			if (pay == 1)
			{
				setRentType(1);
			}
			else if (pay == 2)
			{
				setRentType(5);
			}
			else if (pay == 3)
			{
				setRentType(9);
			}
			else
			{
				setRentType(9);
			}
			break;
		case 3:
			if (pay == 1)
			{
				setRentType(2);
			}
			else if (pay == 2)
			{
				setRentType(6);
			}
			else if (pay == 3)
			{
				setRentType(10);
			}
			else
			{
				setRentType(10);
			}
			break;
		case 4:
			if (pay == 1)
			{
				setRentType(3);
			}
			else if (pay == 2)
			{
				setRentType(7);
			}
			else if (pay == 3)
			{
				setRentType(11);
			}
			else
			{
				setRentType(11);
			}
			break;

		default:
			setRentType(0);
			break;
		}
	}
	
	private void adaptRentTypeSet(int deposit, int pay)
	{
		this.depositNum = deposit;
		this.payNum = pay;
	}
	
	public Integer getRoomType() {
		return roomType;
	}

	public void setRoomType(Integer roomType) {
		this.roomType = roomType;
	}
	
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	public BigDecimal getDeposit() {
		return deposit;
	}

	public void setDeposit(BigDecimal deposit) {
		this.deposit = deposit;
	}

	public BigDecimal getRentPay() {
		return rentPay;
	}

	public void setRentPay(BigDecimal rentPay) {
		this.rentPay = rentPay;
	}

	public BigDecimal getBookPay() {
		return bookPay;
	}

	public void setBookPay(BigDecimal bookPay) {
		this.bookPay = bookPay;
	}

	public String getRentPeriod() {
		return rentPeriod;
	}

	public void setRentPeriod(String rentPeriod) {
		this.rentPeriod = rentPeriod;
	}

	public Date getRentBeginDate() {
		return rentBeginDate;
	}

	public void setRentBeginDate(Date rentBeginDate) {
		this.rentBeginDate = rentBeginDate;
	}

	public Date getRentEndDate() {
		return rentEndDate;
	}

	public void setRentEndDate(Date rentEndDate) {
		this.rentEndDate = rentEndDate;
	}

	public Integer getRentType() {
		return rentType;
	}

	public void setRentType(Integer rentType) {
		this.rentType = rentType;
	}

	public Integer getRentCycleType() {
		return rentCycleType;
	}

	public void setRentCycleType(Integer rentCycleType) {
		this.rentCycleType = rentCycleType;
	}

	public Integer getRentCycle() {
		return rentCycle;
	}

	public void setRentCycle(Integer rentCycle) {
		this.rentCycle = rentCycle;
	}

	public Integer getRentMode() {
		return rentMode;
	}

	public void setRentMode(Integer rentMode) {
		this.rentMode = rentMode;
	}

	public String getModeDt() {
		return modeDt;
	}

	public void setModeDt(String modeDt) {
		this.modeDt = modeDt;
	}

	public Integer getAgreementState() {
		return agreementState;
	}

	public void setAgreementState(Integer agreementState) {
		this.agreementState = agreementState;
	}
	
	public String getChangeInfo() {
		return changeInfo;
	}

	public void setChangeInfo(String changeInfo) {
		this.changeInfo = changeInfo;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public LandlordUser getAgent() {
		return agent;
	}

	public void setAgent(LandlordUser agent) {
		this.agent = agent;
	}
	

	public Integer getRentGrowthType() {
		return rentGrowthType;
	}

	public void setRentGrowthType(Integer rentGrowthType) {
		this.rentGrowthType = rentGrowthType;
	}

	public String getRentGrowthMoney() {
		return rentGrowthMoney;
	}

	public void setRentGrowthMoney(String rentGrowthMoney) {
		this.rentGrowthMoney = rentGrowthMoney;
	}

	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}
	
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	/*@IndexColumn(name="feeIndexCol")*/
	public List<Fee> getFees() {
		return fees;
	}

	public void setFees(List<Fee> fees) {
		this.fees = fees;
	}
	
	public BigDecimal getBalance() {
		return balance;
	}

	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}

	public Integer getDepositNum() {
		return depositNum;
	}

	public void setDepositNum(Integer depositNum) {
		this.depositNum = depositNum;
	}

	public Integer getPayNum() {
		return payNum;
	}

	public void setPayNum(Integer payNum) {
		this.payNum = payNum;
	}

	public Integer getAdvanceNum() {
		return advanceNum;
	}

	public void setAdvanceNum(Integer advanceNum) {
		this.advanceNum = advanceNum;
	}

	public File getPhoto() {
		return photo;
	}

	public void setPhoto(File photo) {
		this.photo = photo;
	}

	public String getPhotoFileName() {
		return photoFileName;
	}

	public void setPhotoFileName(String photoFileName) {
		this.photoFileName = photoFileName;
	}

	public Integer getTenancy() {
		return tenancy;
	}

	public void setTenancy(Integer tenancy) {
		this.tenancy = tenancy;
	}

	public Integer getTenancyType() {
		return tenancyType;
	}

	public void setTenancyType(Integer tenancyType) {
		this.tenancyType = tenancyType;
	}
	
	public BigDecimal getFixedFeeTotalAmount() {
		return fixedFeeTotalAmount;
	}

	public void setFixedFeeTotalAmount(BigDecimal fixedFeeTotalAmount) {
		this.fixedFeeTotalAmount = fixedFeeTotalAmount;
	}
	
	public FeeRecord getLastFeeRecord() {
		return lastFeeRecord;
	}

	public void setLastFeeRecord(FeeRecord lastFeeRecord) {
		this.lastFeeRecord = lastFeeRecord;
	}
	
	public String getRoomName() {
		return roomName;
	}

	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}

	public Integer getRoomId() {
		return roomId;
	}

	public void setRoomId(Integer roomId) {
		this.roomId = roomId;
	}
	
	public String getRoomImageSrc() {
		return roomImageSrc;
	}

	public void setRoomImageSrc(String roomImageSrc) {
		this.roomImageSrc = roomImageSrc;
	}
}
